package com.dq.offer;

import java.util.Arrays;

/**
 * @Author: Dang Qi
 * @Date: 2021/3/16  16:33
 * @Description:
 */
public class NRandomNum {
    public static void main(String[] args) {
        Solution solution = new NRandomNum().new Solution();
        int n = 2;
        System.out.println(Arrays.toString(solution.dicesProbability(n)));
    }
    class Solution {
        public double[] dicesProbability(int n) {
            int N = 6 * n + 1;
            double[] f = new double[N];
            for(int i = 1; i <= 6; i++) f[i] = 1.0/6;

            for(int i = 2; i <= n; i++){
                for(int x = 6*i; x >= i ; x--){
                    double r = 0;
                    for(int j = 1; j <= 6 && x-j > 0; j++){
                        r += f[x-j];
                    }
                    f[x] = r/6.0;
                }
            }
            double[] res = new double[N-n];
            for(int i = n; i < f.length; i++){
                res[i-n] = f[i];
            }
            return res;
        }
    }
}
